package day8;

import java.io.*;
import java.net.Socket;

/**
 * @author oldliu
 * @since 1.0
 */
public class GetFile {
    public static void main(String[] args) {
        Socket s=null;
        try {
            //1:
             s=new Socket("192.168.10.112",8889);
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            //2:发一个文件名
            PrintWriter pw=new PrintWriter(out,true);
            String filename="yuenan.jpg";
            pw.println(filename);
            //3:接受我的内容，
            //4:写入文件
            FileOutputStream fout=new FileOutputStream("D:/tmp/"+filename);
            byte b[]=new byte[50];
            int len=0;
            while ((len=in.read(b))!=-1){
                fout.write(b,0,len);
            }
            fout.close();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                s.close();
            } catch (Exception e) {

            }
        }

    }
}
